<template>
    <div class="getDaily">
        <table align="center" class="mailTable">
            <tr>
                <td class="column">发送人 </td>
                <td class="nrkd">{{ myDailyList.createBy }}</td>
                <td class="column">日期</td>
                <td class="nrkd">{{ parseTime(myDailyList.createTime, '{y}-{m}-{d}') }}</td>
            </tr>
            <tr>
                <td class="column">收件人</td>
                <td class="nrkd" colspan="3" v-html="active == 1 ? myDailyList.sendUserName : readName"></td>
            </tr>
            <tr>
                <td class="column">汇报内容</td>
                <td class="grid-contents" colspan="3" >
                    <div class="center" v-html="myDailyList.content"></div>
                </td>
            </tr>
        </table>

    </div>
</template>
<script setup>
import mydailyStore from "@/store/modules/mydaily";
import {  getReadList } from '@/api/workReport';
const store = mydailyStore();
const date = computed(() => {
    return store.date;
})
const readName = ref('');
//const formDatas = ref({});
const props = defineProps({
    myDailyList: {
        type: Array,
        default: ''
    },
    active: {
        type: Number,
        default: 1
    }
})
const { myDailyList, active } = toRefs(props);
let name = ref(null);
const readList = (id) => {
    let param = {
        id: id
    }
    getReadList(param).then(res => {
        if (res.code === 200) {
            let user = [];
            res.data.map(item => {
                let readName = item.userName + `${item.isRead ? '<span style="color:#999999">（已读）</span>' : '<span style="color:#BE1A21">（未读）</span>'}`; 
                user.push(readName)
            })
            readName.value = user.join(",");
        }
    })
}

watch(myDailyList, (newV, oldV) => {
    if (newV) {
        if (newV.content.indexOf('<img src=\"') != -1) {
            newV.content = newV.content.split('<img src=\"').join('<img src=\"' + import.meta.env.VITE_APP_BASE_API);
        }
        if (active.value == 2) {
            readList(newV.id)
        }
    }
}, { immediate: true });

</script>

<style lang="scss" scoped>
.getDaily {
    max-height: 560px;
    //overflow-y: auto;
    table {
        width: 100%;
        border-right: 1px solid rgba(0, 0, 0, 0.15);
        border-bottom: 1px solid rgba(0, 0, 0, 0.15);
        border-collapse: collapse;
        .getDailyDiv {
            width: 100%;
        }

        tr {
            width: 100%;
            td {
                min-height: 40px;
                border-top: 1px solid rgba(0, 0, 0, 0.15);
                border-left: 1px solid rgba(0, 0, 0, 0.15);
                :deep(img) {
                    width: 200px !important;
                    object-fit: contain;
                }
                .center{
                    max-height: 350px;
                    overflow-y: auto;
                }
            }
        }
    }
}

.bg-purple-light {
    width: 100%;
    .bg-purple {
        background: #F7F7F7;
        width: 20%;
        padding-right: 10px;
        font-weight: bold;
        text-align: center;
        font-size: 14px;
        color: #999999;
    }

    .grid-content {
        width: 30%;
        min-height: 40px;
        height: 40px;
        color: #1E1E1E;
        font-weight: 400;
        line-height: 40px;
        padding-left: 22px;
        overflow-y: auto;

    }

    
}

</style>